package hongcaosp.app.android.wxapi;

import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;

import com.blackchopper.loginshare.constant.Config;
import com.blackchopper.loginshare.messager.Messager;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import xlj.lib.android.base.component.BaseActivity;
import xlj.lib.android.base.toastcompat.ToastManager;


/**
 * 微信支付结果页面
 * Created by deve on 16/6/28.
 */
public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    private IWXAPI api;
    private ApplicationInfo info;
    private String wecahtValue = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            info = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);

            wecahtValue = String.valueOf(info.metaData.get(Config.wechat));
            api = WXAPIFactory.createWXAPI(this, wecahtValue);
            api.handleIntent(getIntent(), this);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void initData(Intent intent) {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected int getLayoutRes() {
        return 0;
    }

    @Override
    public void onReq(BaseReq baseReq) {
        Messager.getInstance().sendReq(baseReq);
    }

    @Override
    public void onResp(BaseResp baseResp) {
        Messager.getInstance().sendResp(baseResp);
        finish();
    }
}
